﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
public partial class q : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request.QueryString["s"]))
        {
            string url="";
            using (MyDb.Db db = new MyDb.Db())
            {
                using (SqlDataReader rs = db.getList(string.Format("select Source from vw_Subject where SubjectID='{0}'", Request.QueryString["s"])))
                {
                    if (rs.Read())
                    {
                        if (rs["Source"].ToString() == "Bus")
                        {
                            using (SqlDataReader rs2 = db.getList(string.Format("select a.BusId,b.RouteID,b.city,b.GoBack from Bus a left join busevent b on b.BusID=a.BusID where a.SubjectID='{0}'", Request.QueryString["s"])))
                            {
                                if (rs2.Read())
                                {
                                    HttpCookie cookie = new HttpCookie("JoySpots");
                                    DateTime dtNow = DateTime.Now;
                                    TimeSpan tsMinute = new TimeSpan(1, 0, 0, 0);
                                    cookie.Expires = dtNow + tsMinute;
                                    url = string.Format("welcome.aspx");
                                    cookie.Values.Add("rtid", rs2["RouteID"].ToString().Trim());
                                    //cookie.Values.Add("rtid", "810");
                                    cookie.Values.Add("city", rs2["city"].ToString().Trim());
                                    cookie.Values.Add("gob", rs2["GoBack"].ToString().Trim());
                                    cookie.Values.Add("busid", rs2["BusID"].ToString().Trim());
                                    Response.AppendCookie(cookie);

                                }
                                rs2.Close();
                            }
                        }
                        else
                        {
                            
                        }
                    }
                    rs.Close();
                }
            }
            if (url != string.Empty) Response.Redirect(url);
        }
    }
}
